home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Var / rxadd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-22  |  6.9 KB  |  305 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     rxadd.c
  5.  
  6.     DESCRIPTION
  7.     Daten an AREXX übergeben
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.  
  13.     TODO
  14.  
  15.     EXAMPLES
  16.  
  17.     SEE ALSO
  18.  
  19.     INDEX
  20.  
  21.     HISTORY
  22.  
  23. ******************************************************************************/
  24.  
  25. /**************************************
  26.         Includes
  27. **************************************/
  28. #include "defs.h"
  29. #include "rexx/rxslib.h"
  30.  
  31. #define PATCH_RXVARS
  32.  
  33. /**************************************
  34.         Globale Variable
  35. **************************************/
  36. Prototype char * GetRexxClip  (char *);
  37. Prototype void     SetRexxClip  (char *, char *);
  38.  
  39.  
  40. Prototype void * currentmsg;
  41.  
  42.  
  43. /**************************************
  44.       Fremde Defines & Strukturen
  45. **************************************/
  46. extern struct RxsLib * RexxSysBase;
  47.  
  48.  
  49. /**************************************
  50.         Interne Variable
  51. **************************************/
  52. void * currentmsg = NULL;    /* the currently active foreign rexxmsg */
  53.  
  54.  
  55.  
  56. /**************************************
  57.        Interne Prototypes
  58. **************************************/
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. #ifdef PATCH_RXCLIPS
  66.  
  67. /*************************************************
  68. **
  69. **  REXX CLIPS INTERFACE
  70. **
  71. **  SetRexxClip()   - set an ARexx Cliplist entry
  72. **  UnsetRexxClip() - remove an ARexx Cliplist entry
  73. **  GetRexxClip()   - get the Value of an ARexx Cliplist entry
  74. **
  75. **  do_setclip()   - COM: set an ARexx Cliplist entry
  76. **  do_unsetclip() - COM: remove an ARexx Cliplist entry
  77. **
  78. **************************************************
  79. **
  80. **  The ARexx Cliplist is searched on every Variable
  81. **  reference
  82. **
  83. **  WARNING - YOU NEED AN EXTENDES HEADERLIST
  84. **  TO COMPILE THESE FUNCTIONS
  85. **  as the std OS20-RX_protos do not reference
  86. **  the following functions:
  87. */
  88. struct Node* FindRsrcNode (struct List*, const char*, long);
  89. void         RemClipNode  (struct Node*);
  90. struct Node* AddClipNode  (struct List*, const char*, long, long);
  91. #pragma libcall RexxSysBase FindRsrcNode b4 9803
  92. #pragma libcall RexxSysBase AddClipNode 1b6 19804
  93. #pragma libcall RexxSysBase RemClipNode 1bc 801
  94. /*
  95. extern Node* FindRsrcNode (__A0 List*, __A1 const char*, __D0 long);
  96. extern void  RemClipNode  (__A0 Node*);
  97. extern Node* AddClipNode  (__A0 List*, __A1 const char*, __D0 long, __D1 long);
  98. **
  99. *************************************************/
  100.  
  101. /*
  102.  *  GetRexxClip
  103.  *
  104.  *  Get a variable from the AREXX - cliplist
  105.  */
  106.  
  107. char*
  108. GetRexxClip ( char * Name )
  109. {
  110.     char        * str;
  111.     struct RexxRsrc * Node;
  112.  
  113.     if ((Name != NULL) && (RexxSysBase != NULL) && (Name[0]!='\0')) { /* correct call */
  114.  
  115.     Node = (struct RexxRsrc *)FindRsrcNode(&RexxSysBase -> rl_ClipList,Name,RRT_CLIP); /* find node */
  116.     if (Node != NULL) {
  117.         str = (char*)malloc(strlen((char*)(Node -> rr_Arg1))+1);  /* alloc string to copy contents of node to */
  118.         if (str != NULL) {
  119.         str=strcpy(str,(char*)(Node -> rr_Arg1));             /* copy contents to str */
  120.         return(str);
  121.         } else {            /* allocation failed */
  122.         nomemory();
  123.         abort (NULL);
  124.         } /* if */
  125.     } /* if */
  126.     } /* if */
  127.     return(NULL);
  128. } /* GetRexxClip */
  129.  
  130.  
  131. /*
  132. *! >SETCIP    name value
  133. *! >UNSETCLIP name
  134. *!
  135. *!  nearly the same as SETENV/UNSETENV but for the REXX-cliplist
  136. *!
  137. */
  138.  
  139. void
  140. UnsetRexxClip (char * name)
  141. {
  142.     struct RexxRsrc *Node;
  143.  
  144.     if (RexxSysBase != NULL) {
  145.     LockBase(RRT_CLIP);
  146.     Node = (struct RexxRsrc *)FindRsrcNode(&RexxSysBase -> rl_ClipList,name,RRT_CLIP);
  147.     if (Node != NULL) {
  148.         RemClipNode(Node);
  149.     } /* if */
  150.     UnlockBase(RRT_CLIP);
  151.     } /* if */
  152. } /* UnsetRexxClip */
  153.  
  154.  
  155. void
  156. SetRexxClip ( char * name, char * value )
  157. {
  158.     struct RexxRsrc *Node;
  159.  
  160.     if (RexxSysBase != NULL) {
  161.     UnsetRexxClip(name);         /* for sure first delete a perhaps existing node - not very fast, but clean(?) */
  162.     LockBase(RRT_CLIP);
  163.     Node = (struct RexxRsrc *)AddClipNode (&RexxSysBase -> rl_ClipList, name, strlen(value), value);
  164.     if (Node == NULL) {
  165.  
  166.         nomemory();
  167.     } /* if */
  168.     UnlockBase(RRT_CLIP);
  169.     } /* if */
  170. } /* SetRexxClip */
  171.  
  172.  
  173. void
  174. do_unsetclip ()
  175. {
  176.     UnsetRexxClip(av[1]);
  177. } /* do_unsetclip */
  178.  
  179.  
  180. void
  181. do_setclip ()
  182. {
  183.     SetRexxClip(av[1], av[2]);
  184. } /* do_setclip */
  185.  
  186.  
  187.  
  188. #endif /* PATCH_RXCLIPS */
  189. #ifdef PATCH_RXVARS
  190.  
  191. #if 0
  192. /*************************************************
  193. **
  194. **  REXX VARIABLE INTERFACE (RVI)
  195. **
  196. **  setrexxvar() - set an ARexx variable
  197. **  getrexxvar() - get the Value of an ARexx variable
  198. **
  199. **  do_setrexx() - COM: set an ARexx variable
  200. **
  201. **************************************************
  202. **
  203. **  The ARexx Variables are checked on every Variable
  204. **  reference
  205. **
  206. **************************************************
  207. **
  208. **  ATTENTION!!!!
  209. **
  210. **    YOU NEED  REXXVARS.O  TO LINK, IF
  211. **    YOU'VE COMPILED WITH "PATCH_RXVARS" DEFINED
  212. **
  213. **    I'll try to recompile rexxVars.o so that
  214. **    No longer on each call to getrexxvar the
  215. **    rexxsyslib.library is opened a 2nd time
  216. **
  217. *************************************************/
  218. /*
  219. **  REXXVARS
  220. **
  221. **  Headers for use with rexxvars.o
  222. */
  223.  
  224.  
  225. extern    __stdargs long CheckRexxMsg(struct Message* msg);
  226. /* Usage: boolean = CheckRexxMsg(message); */
  227.  
  228. extern    __stdargs long GetRexxVar(struct RexxMsg* msg, char* name, char** value);
  229. /* Usage: error = GetRexxVar(message,variable,&value); */
  230.  
  231. extern    __stdargs long SetRexxVar(struct RexxMsg* msg, char* name, char* value, int length);
  232. /* Usage: error = SetRexxVar(message,variable,value,length); */
  233. #endif
  234.  
  235. DEFVARTREE( 88, "RX_", VAR_RX, 3, 3, 0, NULL, NULL, setrexxvar, getrexxvar )
  236.  
  237. /*
  238.  *  setrexxvar / getrexxvar
  239.  *    Rexx Vars functions for Variable support
  240.  */
  241.  
  242. Prototype char * getrexxvar   (char * name);
  243. char *getrexxvar (char *name)
  244. {
  245.     char* val0 = NULL;
  246.     char* val1 = NULL;
  247.     long err;
  248.  
  249.     if (currentmsg == NULL) {
  250.     /* error ("Cannot get RxVars\nwithout a pending RxMsg"); */ /* can not be called if we check tha routine at every var-expansion */
  251.     return (NULL);
  252.     } /* if */
  253.  
  254.     err = GetRexxVar((void*)currentmsg, name, &val0);
  255.     if (val0 && !err) {
  256.     val1 = malloc(strlen(val0)+1);
  257.     if (val1) {
  258.         strcpy(val1, val0);
  259.     } else {
  260.         nomemory();
  261.         return (NULL);
  262.     } /* if */
  263.     } /* if */
  264.  
  265.     return(val1);
  266. } /* getrexxvar */
  267.  
  268.  
  269. Prototype void     setrexxvar   (char * name, char * value);
  270. void setrexxvar (char * name, char * value)
  271. {
  272.     long err;
  273.  
  274.     if (currentmsg == NULL) {
  275.     error ("%s:\nCannot set RxVars\nwithout a pending RxMsg", av[0]);
  276.     return;
  277.     } /* if */
  278.  
  279.     err = SetRexxVar((void*)currentmsg, name, value, strlen(value));
  280. /* printf ("setting rxvar %s to %s - %ld\n", name, value, err); */
  281.     if (err) {
  282.     SET_ABORTION( 1 );
  283.     } /* if */
  284. } /* setrexxvar */
  285.  
  286. /*
  287. *! >SETREXX
  288. *!    Interface to use Variables from Arexx Programs
  289. *!
  290. *!  NOTE: UNSETREXX does NOT exist
  291. *!
  292. */
  293.  
  294. DEFUSERCMD("SetRexx", 2, CF_COK|CF_VWM|CF_ICO|0, void, do_setrexx, (void), )
  295. {
  296.     setrexxvar(av[1], av[2]);
  297. } /* do_setrexx */
  298.  
  299.  
  300. #endif /* PATCH_RXVARS */
  301. /******************************************************************************
  302. *****  ENDE rxadd.c
  303. ******************************************************************************/
  304.  
  305.